package project.teg.common;

import java.util.Date;
import java.util.Random;
import project.teg.common.types.BorderType;
import android.graphics.Color;
import android.graphics.Point;
import android.util.Log;


//********************		DEPRECATED FOR NOW!!!!!!!!!!		**************************
public class Methods {
	Random random = new Random(new Date().getTime());
	public int sirina = 320, visina = 355, brojMjerenja;

	public Methods(int width, int height) {
		this.sirina = width;
		this.visina = height;
	}

	public int IzracunajVelicinuObjekta() {
		return random.nextInt(21) + 10;
	}

	public Point IzracunajPolozajObjekta(int velicinaObjekta) {
		Log.e("sirina, visina", sirina + ", " + visina);

		return new Point(random.nextInt(sirina - velicinaObjekta),
				random.nextInt(visina - velicinaObjekta));
	}

	public int IzracunajBojuObjekta() {
		Random r = new Random(new Date().getTime());
		return Color.BLUE;		
	}

	public Border IzracunajRub(int velicinaObjekta, Point polozajObjekta) {

		//Treba uvesti nove dijelove ekrana
		Border rub = new Border();
		rub.distanceFromBorder = sirina > visina ? sirina : visina;
		int gore = polozajObjekta.y;
		int dolje = visina - polozajObjekta.y + velicinaObjekta;
		int lijevo = polozajObjekta.x;
		int desno = sirina - polozajObjekta.x + velicinaObjekta;

		if (rub.distanceFromBorder > gore) {
			rub.distanceFromBorder = gore;
			rub.borderType = BorderType.Up;
		}
		if (rub.distanceFromBorder > dolje) {
			rub.distanceFromBorder = dolje;
			rub.borderType = BorderType.Down;
		}
		if (rub.distanceFromBorder > lijevo) {
			rub.distanceFromBorder = lijevo;
			rub.borderType = BorderType.Left;
		}
		if (rub.distanceFromBorder > desno) {
			rub.distanceFromBorder = desno;
			rub.borderType = BorderType.Right;
		}
		return rub;
	}

	public Border IzracunajRub(int sirinaObjekta, int visinaObjekta,
			Point polozajObjekta) {

		Border rub = new Border();
		rub.distanceFromBorder = sirina > visina ? sirina : visina;
		int gore = polozajObjekta.y;
		int dolje = visina - polozajObjekta.y - visinaObjekta;
		int lijevo = polozajObjekta.x;
		int desno = sirina - polozajObjekta.x - sirinaObjekta;

		if (rub.distanceFromBorder > gore) {
			rub.distanceFromBorder = gore;
			rub.borderType = BorderType.Up;
		}
		if (rub.distanceFromBorder > dolje) {
			rub.distanceFromBorder = dolje;
			rub.borderType = BorderType.Down;
		}
		if (rub.distanceFromBorder > lijevo) {
			rub.distanceFromBorder = lijevo;
			rub.borderType = BorderType.Left;
		}
		if (rub.distanceFromBorder > desno) {
			rub.distanceFromBorder = desno;
			rub.borderType = BorderType.Right;
		}
		return rub;
	}

	public int IzracunajKvadrant(int velicinaObjekta, Point polozajObjekta) {
		int kvadrant;
		if (polozajObjekta.x > sirina / 2)
			if (polozajObjekta.y > visina / 2)
				kvadrant = 4;
			else
				kvadrant = 3;
		else if (polozajObjekta.y > visina / 2)
			kvadrant = 2;
		else
			kvadrant = 1;
		return kvadrant;
	}
}
